﻿using System.ComponentModel;
using DataBases;
using Microsoft.Practices.Prism.Commands;

namespace SlXnaApp1.ViewModel
{
    public class GamePageViewModel : INotifyPropertyChanged
    {
        private int _userScore;
        public int UserScore
        {
            get { return _userScore; }
            set { _userScore = value; RaisePropertyChanged("UserScore"); }
        }

        private string _userName;
        public string UserName
        {
            get { return _userName; }
            set { _userName = value; RaisePropertyChanged("UserName"); }
        }

        private readonly DelegateCommand _saveCommand;
        public DelegateCommand SaveCommand
        {
            get
            {
                return _saveCommand;
            }
        }

        public GamePageViewModel()
        {
            _saveCommand = new DelegateCommand(Save);
            _userScore = 0;
            _userName = Model.Settings.GetDefaultUserName();
        }

        private void Save()
        {
            DBHelper.AddSets(new ScoreSet{UserName = UserName, UserScore = UserScore});
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
